package com.wc.算法基础课.E第五讲动态规划.区间DP.游戏;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/29 12:25
 * @description https://www.acwing.com/solution/content/32865/
 */
public class Main {
    // 思路：f[i][j]表示状态为[i,j]区间时候能获得的最大值, s[i,j]是所有
    // 如果取左边,那剩下的状态就是f[i + 1][j]了, s[i,j] - f[i + 1][j]
    //    取右边，             f[i][j - 1]  , s[i,j] - f[i][j - 1]

    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 110;
    static int[][] f = new int[N][N];
    static int[] a = new int[N];
    static int[] s = new int[N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            a[i] = sc.nextInt();
            s[i] = s[i - 1] + a[i];
        }
        for (int len = 1; len <= n; len++) {
            for (int st = 1; st + len - 1 <= n; st++) {
                int ed = st + len - 1;
                // 取左边
                f[st][ed] = Math.max(f[st][ed], s[ed] - s[st - 1] - f[st + 1][ed]);
                // 取右边
                f[st][ed] = Math.max(f[st][ed], s[ed] - s[st - 1] - f[st][ed - 1]);
            }
        }
        out.println(f[1][n] + " " + (s[n] - f[1][n]));
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}